import VueRouter from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import HomePage from '@/views/HomePage/HomePage'
import ChinaMap from '@/views/ChinaMap/ChinaMap'
import Vue from 'vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: '测试平台',
    component: HomeView,
    children: [
      {
        path: 'home',
        name: '首页',
        component: HomePage,
      }, {
        path: 'chinaMap',
        name: '中国地图',
        component: ChinaMap,
      }
    ]
  },
]

const router = new VueRouter({
  history: '',
  routes
})

router.beforeEach((to, from, next) => {
  console.log(process.env.VUE_APP_HOST);
  next()
})

router.afterEach((to, from) => {
  console.log(to, from);
})

router.onError((error) => {
  const pattern = /Loading chunk chunk-(.*)+ failed/g
  const loadFailed = error.message.match(pattern)
  if (loadFailed) {
    location.reload()
  }
})

export default router
